package com.visionet.waveletData.web.common.utils;
import java.io.UnsupportedEncodingException;


public class UnicodeUtil {

	/**
	 * 表情转unicode 
	 * @param gbString
	 * @return
	 */
	   public static String gbEncoding(final String gbString) {   
		      char[] utfBytes = gbString.toCharArray();   
		            String unicodeBytes = "";   
		             for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) {   
		                  String hexB = Integer.toHexString(utfBytes[byteIndex]);   
		                  if(hexB.toUpperCase().compareTo("A000")<=0){
		                	  unicodeBytes= unicodeBytes + utfBytes[byteIndex];   
		                	  continue;
		                  }
//		                    if (hexB.length() <= 2) {   
//		                        hexB = "00" + hexB;   
//		                   }   
		                    unicodeBytes = unicodeBytes + "\\u" + hexB;   
		                }   
		                System.out.println("unicodeBytes is: " + unicodeBytes);   
		                return unicodeBytes;   
		           }   
		          
		          public static String decodeUnicode(final String dataStr) {   
		        	  String s=dataStr;
		             int start = 2;   
		               int end = 6;   
		              final StringBuffer buffer = new StringBuffer();   
		              s =dataStr;
		               while (true) { 
		            	   if(s.equals("")){
		            		    return buffer.toString();   
		            	   }
		            	   if(!s.startsWith("\\u") ){
		            		   buffer.append(s.substring(0, 1));
		            		   s=s.substring(1);
		            		   continue;
		            	   }
		                   String charStr = "";   
		                   charStr = s.substring(start, end);   
		                   s=s.substring(end);
		                   char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。   
		                 buffer.append(new Character(letter).toString());   
		                // start = end;   
		               }   
		           }     
}
